-
Notifications
You must be signed in to change notification settings - Fork 1.2k
SSZ-QL: calculate generalized indices for elements #15873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
SSZ-QL: calculate generalized indices for elements #15873
Conversation
… no recursion. Extended test coverage for bitlist and bitvectors. vectors need more testing
…he beginning. Swap to regex to gain flexibility.
// Helpers for input processing | ||
|
||
// processPathElement processes a path element string and returns an Element struct | ||
func processPathElement(elementStr string) (Element, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these path-related processing can be done at path.go
, so GetGeneralizedIndexFromPath
won't process the path again. So Element
in this file can be merged with PathElement
(I'm not sure I've understood the PR description correctly but I think so)
One other concern for elementStr
is that it's the result of ParsePath
, which means the index
information will probably be parsed. For example, if a path is like "bitlist_field[1]"
, then PathElement
would look like:
&query.PathElement{
Name: "bitlist_field",
Index: &1 // pointer to uint64
}
} | ||
return (bitlistInfo.Limit() + 255) / bitsPerChunk, nil // Bits are packed into 256-bit chunks | ||
case Bitvector: | ||
vectorInfo, err := info.BitvectorInfo() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vectorInfo, err := info.BitvectorInfo() | |
bitvectorInfo, err := info.BitvectorInfo() |
Just a nit!
return 0, err | ||
} | ||
elemLength := itemLengthFromInfo(elementInfo) | ||
return (vectorInfo.Length()*uint64(elemLength) + 31) / bytesPerChunk, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return (vectorInfo.Length()*uint64(elemLength) + 31) / bytesPerChunk, nil | |
return (vectorInfo.Length()*elemLength + 31) / bytesPerChunk, nil |
Other nit, we don't need type cast here as it is already uint64
. Same comment for List
case above.
return 0, fmt.Errorf("len() is only supported for List and Bitlist types, got %s", fieldSsz.sszType) | ||
} | ||
currentInfo = &sszInfo{sszType: UintN, fixedSize: 8} | ||
root = updateRoot(root, 1, 2, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
root = updateRoot(root, 1, 2, 1) | |
root = root*2 + 1 |
I think we can simply put the calculation here
default: | ||
return 0, fmt.Errorf("indexing not supported for type %s", fieldSsz.sszType) | ||
} | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continue |
We might remove continue
here
multiplier = nextPowerOfTwo(innerChunkCount) | ||
offset = *idx | ||
} | ||
root = updateRoot(root, 1, multiplier, offset) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use innerChunkCount
instead of multiplier
here, as List
and Vector
would probably share same logic of calculating root index?
What type of PR is this?
Feature
Which issues(s) does this PR fix?
Partially #15598
What does this PR do? Why is it needed?
This PR develop a way to calculate the Generalized Indices of a given path within a SSZ Object. To do so, it follows Consensus Spec's Merkle proofs.
A conversion from PathElement to Generalized Index is necessary to work with fastssz proofs library.
The code implemented walks the path within the SSZInfo struct in a consensus layer spec way. We have to take into account that the "path" input is slightly different:
The pythonic version expects a Path input
[FieldA,"FieldB",3]
while the Go version expectsfield_a.field_b[3]
.Other notes for review
a. In the case of "basic types", it is due to how the
GetGeneralizedIndexFromPath
is coded.b. For the "Vector" type, I tried to create new custom types as per the following example:
But it fails to generate the Go wrappers.
Acknowledgements